/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package com.ssm.changeunit;

import com.ssm.changeunit.persistance.ManagedItemListDAO;
import com.ssm.changeunit.persistance.ManagedItemListDTO;
import com.ssm.changeunit.persistance.PersistanceException;

/**
 *
 * @author 시리우스
 */
public class ManagedItemListFactory extends AbstractFactory {
    @Override
    public ManagedItemList createProduct(String filePath) throws CreateException {
        try {
            ManagedItemListDAO managedItemListDAO = new ManagedItemListDAO();
            
            ManagedItemListDTO managedItemListDTO = managedItemListDAO.find(filePath);
            
            if(managedItemListDTO == null) {
                managedItemListDTO = new ManagedItemListDTO();
                
                managedItemListDTO.setFilePath(filePath);
                
                managedItemListDAO.insert(managedItemListDTO);
            }
            
            return new ManagedItemList(filePath);
        }
        catch(PersistanceException ex) {
            throw new CreateException("ManagedItemList를 생성하는데 실패했습니다.", ex);
        }
    }
}
